/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.nacos.core.storage.kv;

import com.alibaba.nacos.core.exception.KvStorageException;

import java.util.List;
import java.util.Map;

/**
 * 通用键值存储接口.
 *
 * @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
 */
public interface KvStorage {

    enum KvType {
        /**
         * 本地文件存储.
         */
        File,

        /**
         * 本地内存存储.
         */
        Memory,

        /**
         * RocksDB存储.
         */
        RocksDB,
    }


    /**
     * 通过键获取数据.
     *
     * @param key 要获取数据的键
     * @return 键对应的数据
     * @throws KvStorageException KVStorageException
     */
    byte[] get(byte[] key) throws KvStorageException;

    /**
     * 批量获取数据.
     *
     * @param keys 数据键列表
     * @return 键值对格式的数据
     * @throws KvStorageException KvStorageException
     */
    Map<byte[], byte[]> batchGet(List<byte[]> keys) throws KvStorageException;

    /**
     * 存储数据.
     *
     * @param key   数据键
     * @param value 数据值
     * @throws KvStorageException KvStorageException
     */
    void put(byte[] key, byte[] value) throws KvStorageException;

    /**
     * 批量存储数据.
     *
     * @param keys   批量数据键
     * @param values 批量数据值
     * @throws KvStorageException KvStorageException
     */
    void batchPut(List<byte[]> keys, List<byte[]> values) throws KvStorageException;

    /**
     * 删除数据.
     *
     * @param key 要删除的数据键
     * @throws KvStorageException KvStorageException
     */
    void delete(byte[] key) throws KvStorageException;

    /**
     * 批量删除数据.
     *
     * @param keys 要删除的数据键列表
     * @throws KvStorageException KvStorageException
     */
    void batchDelete(List<byte[]> keys) throws KvStorageException;

    /**
     * 创建快照.
     *
     * @param backupPath 快照文件地址
     * @throws KvStorageException KVStorageException
     */
    void doSnapshot(final String backupPath) throws KvStorageException;

    /**
     * 加载快照.
     *
     * @param path 快照文件地址
     * @throws KvStorageException KVStorageException
     */
    void snapshotLoad(String path) throws KvStorageException;

    /**
     * 获取所有键.
     *
     * @return all keys
     * @throws KvStorageException KVStorageException
     */
    List<byte[]> allKeys() throws KvStorageException;

    /**
     * 关机.
     */
    void shutdown();

}
